<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>Signin · LEARN</title>
        <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
        <link href="/static/css/signin.css" rel="stylesheet">
    </head>
    <body class="text-center">
        <div class="form-signin">
            <img class="mb-4 rounded" src="/static/img/Logo.png" width="100" height="100">
            <h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
            <label class="sr-only">Username</label>
            <input type="text" id="username" class="form-control" placeholder="Username" required autofocus>
            <label class="sr-only">Password</label>
            <input type="password" id="password" class="form-control" placeholder="Password" required>
            <button class="btn btn-lg btn-primary btn-block" id="submit">Sign in</button>
            <a href="/register1.htm">SignUp</a>
            <p class="mt-5 mb-3 text-muted">&copy;Learners' Engineering and Research Network</p>
        </div>
        <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script>
            $('#submit').click(function () {
                $.ajax({
                    type: 'post',
                    url: 'signin.htm',
                    async:false,
                    data: {
                        'type':'login',
                        'username': $('#username').val(),
                        'password': $('#password').val()
                    },
                    success: function(result, t) {
                        if (result == 'success') {
                            document.cookie = `username=${$('#username').val()};path=/`;
                            document.cookie = `password=${$('#password').val()};path=/`;
                            location.href = '/explore.htm';
                        } else alert(result);
                    },
                    error: function (http, e) {
                        alert(http.status + e);
                    }
                });
            });
        </script>
    </body>
</html>
